XSL; /** * Filters the content of the sitemap stylesheet. * * @since 5.5.0 * * @param string $xsl_content Full content for the XML stylesheet. */ return apply_filters( 'wp_sitemaps_stylesheet_content', $xsl_content ); } /** * Returns the escaped XSL for the index sitemaps. * * @since 5.5.0 */ public function get_sitemap_index_stylesheet() { $css = $this->get_stylesheet_css(); $title = esc_xml( __( 'XML Sitemap' ) ); $description = esc_xml( __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' ) ); $learn_more = sprintf( '%s', esc_url( __( 'https://www.sitemaps.org/' ) ), esc_xml( __( 'Learn more about XML sitemaps.' ) ) ); $text = sprintf( /* translators: %s: Number of URLs. */ esc_xml( __( 'Number of URLs in this XML Sitemap: %s.' ) ), '' ); $lang = get_language_attributes( 'html' ); $url = esc_xml( __( 'URL' ) ); $lastmod = esc_xml( __( 'Last Modified' ) ); $xsl_content = << {$title}

{$title}

{$description}

{$learn_more}

{$text}

{$url} {$lastmod}
XSL; /** * Filters the content of the sitemap index stylesheet. * * @since 5.5.0 * * @param string $xsl_content Full content for the XML stylesheet. */ return apply_filters( 'wp_sitemaps_stylesheet_index_content', $xsl_content ); } /** * Gets the CSS to be included in sitemap XSL stylesheets. * * @since 5.5.0 * * @return string The CSS. */ public function get_stylesheet_css() { $text_align = is_rtl() ? 'right' : 'left'; $css = <<where( 'ip', $ip ) ->where( 'status', self::STATUS_BLOCKED ) ->first(); } /** * Maybe unblock IP? * * @param string $ip The IP address to search for. * * @return string */ public static function get_unlocked_ip_by( $ip ) { $orm = self::get_orm(); $model = $orm->get_repository( self::class ) ->where( 'ip', $ip ) ->first(); if ( is_object( $model ) ) { $model->status = self::STATUS_NORMAL; $orm->save( $model ); return $model->ip; } return ''; } /** * Retrieves bulk IPs based on the provided status, IPs, and limit. * * @param string $status The status of the IPs to retrieve. * @param array|null $ips An array of IPs to retrieve. If null, retrieves all IPs with the given status. * @param int|string|null $limit The maximum number of IPs to retrieve. If null, retrieves all IPs. * * @return array An array of IP models. */ public static function get_bulk( string $status, $ips = null, $limit = null ) { $orm = self::get_orm(); $builder = $orm->get_repository( self::class ); if ( null === $ips ) { $builder->where( 'status', $status ); } if ( null !== $ips ) { $builder->where( 'ip', 'in', $ips ); } if ( null !== $limit ) { $builder->limit( $limit ); } return $builder->get(); } /** * Get the access status of this IP. * * @return array */ public function get_access_status(): array { $settings = wd_di()->get( Blacklist_Lockout::class ); if ( ! in_array( $this->ip, $settings->get_list( 'blocklist' ), true ) && ! in_array( $this->ip, $settings->get_list( 'allowlist' ), true ) ) { return array( 'na' ); } $result = array(); if ( in_array( $this->ip, $settings->get_list( 'blocklist' ), true ) ) { $result[] = 'banned'; } if ( in_array( $this->ip, $settings->get_list( 'allowlist' ), true ) ) { $result[] = 'allowlist'; } return $result; } /** * Returns the text representation of the access status based on the given status code. * * @param string $status The status code to determine the access status text for. * Possible values are: 'banned', 'allowlist', 'na'. * * @return string The text representation of the access status. * Returns an empty string if the status code is not recognized. */ public function get_access_status_text( string $status ): string { switch ( $status ) { case 'banned': return esc_html__( 'Banned', 'wpdef' ); case 'allowlist': return esc_html__( 'In Allowlist', 'wpdef' ); case 'na': return esc_html__( 'Not banned or in allowlist', 'wpdef' ); default: return ''; } } /** * Get locked IPs. * * @return array */ public static function query_locked_ip(): array { $orm = self::get_orm(); $time = new DateTime( 'now', wp_timezone() ); return $orm->get_repository( self::class ) ->select( 'id,ip,status' ) ->where( 'status', self::STATUS_BLOCKED ) ->where( 'release_time', '>', $time->getTimestamp() ) ->group_by( 'ip' ) ->order_by( 'lock_time', 'desc' ) ->get_results(); } /** * Checks if the current object is locked. * * @return bool Returns false if the object is not locked, true otherwise. */ public function is_locked(): bool { if ( self::STATUS_BLOCKED === $this->status ) { $time = new DateTime( 'now', wp_timezone() ); if ( $this->release_time < $time->getTimestamp() ) { // Unlock it and clear the metadata. $this->attempt = 0; $this->meta = array( 'nf' => array(), 'login' => array(), ); $this->status = self::STATUS_NORMAL; $this->save(); return false; } else { return true; } } return false; } /** * Return remaining release time. * * @return int Remaining release time. */ public function remaining_release_time(): int { $time = new DateTime( 'now', wp_timezone() ); return $this->release_time - $time->getTimestamp(); } /** * Remove all records. * * @return bool|int * @since 3.3.0 */ public static function truncate() { $orm = self::get_orm(); return $orm->get_repository( self::class )->truncate(); } }